
package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class AddressBook here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class AddressBook
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> persons;
    private Person person;

    /**
     * Constructor for objects of class AddressBook
     */
    public AddressBook()
    {
        persons = new ArrayList<Person>();
    }
    
    public void addPerson(Person person)
    {
        persons.add(person);
    }
    public void deletePerson(long id)
    {
        Person person = findPerson(id);
        persons.remove(person);
    }
    public Person findPerson(long id)
    {
        Person person = null;
        boolean found = false;
        int index = 0;
        while(index < persons.size() && !found)
        {
            person = persons.get(index);
            if(person.getId() == id)
            {
                found = true;
            }
            else{
                index++;
            }
        }//end while
        if(found){
             return persons.get(index);
        }
        else{
            return null;
        }
    }
    public void makePersonList()
    {
        for(Person person : persons) 
        {
            System.out.println(person.getName());
        }
}
}
